<template>
  <div class="page-container">
    <div v-if="user">
      <el-row :gutter="20">
        <!--左边用户卡片-->
        <el-col :span="6" :xs="24">
          <user-card :user="user"/>
        </el-col>
        <!--账户信息-->
        <el-col :span="18" :xs="24">
          <el-card>
            <el-tabs v-model="activeTab">
              <el-tab-pane label="账户信息" name="account">
                <account :user="user"/>
              </el-tab-pane>
              <el-tab-pane label="修改密码" name="password">
                <password/>
              </el-tab-pane>
            </el-tabs>
          </el-card>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
  import UserCard from './UserCard'
  import Account from './Account'
  import Password from './Password'

  export default {
    name: 'Main',
    components: {UserCard, Account, Password},
    data() {
      return {
        user: {},

        activeTab: 'account'
      }
    },
    mounted(){
      // 根据传入的参数 展现不同的tab页
      let activeTab = this.$route.query.activeTab;
      if (activeTab) {
        this.activeTab = activeTab;
      }
    },
    created() {
      this.getUser()
    },
    methods: {
      getUser() {
        this.$api.user.findLoginUserMsg().then((res) => {
          this.user = res.data;
        });
      }
    }
  }
</script>

